{{ define "content" }}
<div class="page-title">
    <div class="title_left">
        <h3>{{ i18n "Bind %s logs" $ nil nil nil .bind.ID }}</h3>
    </div>

    <div class="title_right">
        <div class="form-group pull-right">
            <div class="input-group">
                <label class="btn-group">
                    <form action="?clean=1" method="post">
                    <button type="submit" class="btn btn-icon btn-danger btn-sm"
                            data-toggle="modal" data-target="#modal"
                            data-modal-title="{{ i18n "Confirm clean logs" . }}"
                            data-modal-body="{{ i18n "Are you sure?" . }}"
                            data-modal-callback="action('reset');">
                        <i class="fas fa-eraser" title="{{ i18n "Clean" . }}"></i>
                    </button>
                    </form>
                </label>
            </div>
        </div>
    </div>
</div>

<div class="clearfix"></div>

<div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12">
        <div class="x_panel">
            <div class="x_content">
                <div class="table-responsive">
                    <table class="table table-hover table-striped datatable dt-responsive nowrap" id="logs" style="width:100%">
                        <thead>
                        <tr>
                            <th>{{ i18n "#" . }}</th>
                            <th>{{ i18n "Time" . }}</th>
                            <th>{{ i18n "Level" . }}</th>
                            <th>{{ i18n "Message" . }}</th>
                            <th>{{ i18n "Context" . }}</th>
                        </tr>
                        </thead>
                        <tbody>
                        {{ range $i, $log := reverse .logs }}
                            <tr>
                                <td>{{ add1 $i }}</td>
                                <td>{{ $log.Time.Format "2006-01-02T15:04:05-07:00" }}</td>
                                <td>
                                    {{ if eq $log.Level "debug" }}
                                        <span class="label label-primary">{{ $log.Level }}</span>
                                    {{ else if eq $log.Level "info" }}
                                        <span class="label label-info">{{ $log.Level }}</span>
                                    {{ else if eq $log.Level "warn" }}
                                        <span class="label label-warning">{{ $log.Level }}</span>
                                    {{ else if eq $log.Level "error" }}
                                        <span class="label label-danger">{{ $log.Level }}</span>
                                    {{ else if eq $log.Level "panic" }}
                                        <span class="label label-danger">{{ $log.Level }}</span>
                                    {{ else if eq $log.Level "fatal" }}
                                        <span class="label label-danger">{{ $log.Level }}</span>
                                    {{ else }}
                                        <span class="label label-success">{{ $log.Level }}</span>
                                    {{ end }}
                                </td>
                                <td><pre><code>{{ $log.Message|raw }}</code></pre></td>
                                <td>
                                    {{ if $log.Context }}
                                    <pre><code class="yaml">{{ $log.Context|raw }}</code></pre>
                                    {{ end }}
                                </td>
                            </tr>
                        {{ end }}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{{ end }}

{{ define "head" }}
    {{ staticHTML (staticURL "/dashboard/assets/vendors/datatables.net-bs/css/dataTables.bootstrap.min.css" false) }}
    {{ staticHTML (staticURL "/dashboard/assets/vendors/datatables.net-fixedheader-bs/css/fixedHeader.bootstrap.min.css" false) }}
    {{ staticHTML (staticURL "/dashboard/assets/vendors/datatables.net-responsive-bs/css/responsive.bootstrap.min.css" false) }}
    {{ staticHTML (staticURL "/dashboard/assets/vendors/highlightjs/css/tomorrow.min.css" false) }}
{{ end }}

{{ define "js" }}
    {{ staticHTML (staticURL "/dashboard/assets/vendors/datatables.net/js/jquery.dataTables.min.js" false) }}
    {{ staticHTML (staticURL "/dashboard/assets/vendors/datatables.net-bs/js/dataTables.bootstrap.min.js" false) }}
    {{ staticHTML (staticURL "/dashboard/assets/vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js" false) }}
    {{ staticHTML (staticURL "/dashboard/assets/vendors/datatables.net-responsive/js/dataTables.responsive.min.js" false) }}
    {{ staticHTML (staticURL "/dashboard/assets/vendors/datatables.net-responsive-bs/js/responsive.bootstrap.min.js" false) }}
    {{ staticHTML (staticURL "/dashboard/assets/vendors/highlightjs/js/highlight.pack.min.js" false) }}

    <script type="application/javascript">
        $(document).ready(function () {
            var table = $('#logs');

            table.one('init.dt', function () {
                table.DataTable().rows().every(function (i) {
                    var data = this.data();
                    data[1] = data[1].length > 0 ? dateToString(data[1]) : '';
                    this.row(i).data(data);
                });
            });
        });
    </script>
{{ end }}
